<template>
	<view class="serve">
		<view class="nav">
			<u-tabs :list="list1" lineColor="#FF5B1A" :activeStyle="{color: '#FF5B1A'}" @click="change"
				:scrollable="false"></u-tabs>
		</view>
		<scroll-view scroll-y="true" class="main" @scrolltolower="lower()">
			<view class="list" v-for="(item,index) of list">
				<image :src="oss(item.hire.avatar)" class="cover" mode=""></image>
				<view class="info">
					<view class="title">
						<view class="l">{{item.hire.nickname}}</view>
						<view class="r" v-if="type === 0">待付款</view>
						<view class="r" v-if="type === 1">已付款</view>
						<view class="r" v-if="type === 2">已完成</view>
						<view class="r" v-if="type === -1">申请退款</view>
						<view class="r" v-if="type === -2">已退款</view>
					</view>

					<view class="num">
						<view class="l"><text class="type">服务项目</text>
							<view class="word">{{item.name}}</view>
						</view>
						<view class="r"><text class="icon">¥</text>{{item.price}}/{{item.skill.unit_price}}</view>
					</view>
					<view class="other">
						<view class="l" @click="tel(item.hire.mobile)">联系服务人员</view>
						<view class="r" v-if="type === 0" @click="cancelpay(item.id)">取消</view>
						<view class="r" v-if="type === 0" @click="authTo(`pages/common/repay?id=${item.id}&money=${item.price}`)">去支付</view>
						<view class="r btn" v-if="type === 1" @click="cancel(item.id)">申请退款</view>
						<view class="r btn" v-if="type === 1" @click="sure(item.id)">已完成</view>
					</view>
				</view>
			</view>
			<u-empty v-if="list.length === 0 && finish" mode="data" marginTop="100">
			</u-empty>
			
		</scroll-view>
		<u-modal :show="show"  title="确定要申请退款吗" @confirm="confirm" @cancel="show = false" :showCancelButton="true"></u-modal>
		<u-modal :show="show1"  title="服务项目确定完成了吗？" @confirm="confirm1" @cancel="show1 = false" :showCancelButton="true"></u-modal>
		<u-modal :show="show2"  title="确定取消吗？" @confirm="confirm2" @cancel="show2 = false" :showCancelButton="true"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list1: [{
					name: '待付款',
					type: 0
				}, {
					name: '已付款',
					type: 1
				}, {
					name: '已完成',
					type: 2
				}, {
					name: '退款中',
					type: -1
				}, {
					name: '已退款',
					type: -2
				}],
				page: 1,
				finish: false,
				type: 0,
				list: [],
				show: false,
				show1: false,
				show2: false,
				id: ''
			};
		},
		onShow() {
			this.reload()
		},
		methods: {
			sure(id) {
				this.show1 = true
				this.id = id
			},
			cancelpay(id) {
				this.show2 = true
				this.id = id
			},
			cancel(id) {
				this.show = true
				this.id = id
			},
			confirm2() {
				this.show2 = false
				uni.$u.http.post('/userhire', {
					types: 'cancel',
					id: this.id
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast(res.msg)
						this.reload()
					}
				}).catch((res) => {
						
				})
			},
			confirm() {
					this.show = false
					uni.$u.http.post('/userhire', {
						types: 'apply',
						id: this.id
					}).then(res => {
						if (res.code == 1) {
							uni.$u.toast(res.msg)
							this.reload()
						}
					}).catch((res) => {
							
					})
			},
			confirm1() {
					this.show1 = false
					uni.$u.http.post('/userhire', {
						types: 'finish',
						id: this.id
					}).then(res => {
						if (res.code == 1) {
							uni.$u.toast(res.msg)
							this.reload()
						}
					}).catch((res) => {
							
					})
			},
			tel(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				});
			},
			change(e) {
				console.log(e)
				this.type = e.type
				this.reload()
			},
			reload() {
				this.page = 1
				this.finish = false
				this.list = []
				this.getList()
			},
			lower() {
				this.page++
				this.getList()
			},
			getList() {
				if (this.finish) {
					return
				}
				uni.$u.http.post('/userhire', {
					page: this.page,
					type: this.type
				}).then(res => {
					if (res.code == 1) {
						this.list = this.list.concat(res.data)
						if (res.data.length === 0) {
							this.finish = true
						}
					}
				}).catch((res) => {

				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		background: #f6f6f6;
	}

	.serve {
		height: 100%;
		position: relative;
	}

	.nav {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 90rpx;
	}

	.main {
		position: absolute;
		left: 0;
		width: 100%;
		bottom: 0;
		top: 90rpx;

		.list {
			display: flex;
			margin: 0 20rpx 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 10rpx;
			position: relative;

			.cover {
				width: 170rpx;
				height: 170rpx;
				margin-right: 20rpx;
				flex-direction: 0;
				border-radius: 10rpx;
			}

			.address {
				font-size: 25rpx;
				color: #575859;
				margin: 10rpx 0 20rpx;
			}

			.info {
				flex: 1;

				.title {
					display: flex;
					align-items: center;

					.l {
						flex: 1;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						font-weight: bold;
					}

					.r {
						color: #428DFC;
						font-size: 24rpx;
						flex-shrink: 0;
						display: flex;
						align-items: center;
					}
				}

				.other {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.l {
						font-size: 28rpx;
						color: #333;
					}

					.r {
						font-size: 28rpx;
						color: #333;
					}
					.btn{
						padding: 2rpx 8rpx;
						border: 1px solid #FF8007;
						color: #FF8007;
						border-radius: 4rpx;
						font-size: 24rpx;
					}
				}

				.num {
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin: 20rpx 0;

					.l {
						display: flex;
						align-items: center;

						.type {
							color: #999999;
							font-size: 24rpx;
						}

						.word {
							background-color: #FFFAE5;
							height: 36rpx;
							border-radius: 18rpx;
							color: #FF8007;
							font-size: 20rpx;
							padding: 0 20rpx;
							display: flex;
							align-items: center;
						}
					}

					.r {
						color: #FF5B1A;
						font-size: 40rpx;

						.icon {
							font-size: 28rpx;
						}
					}
				}
			}
		}
	}
</style>
